package org.jetlinks.community.standalone.configuration;


import org.hswebframework.ezorm.rdb.mapping.jpa.JpaEntityTableMetadataParser;
import org.hswebframework.ezorm.rdb.mapping.parser.DefaultValueCodecResolver;
import org.jetlinks.community.mapping.annotation.EnhanceDateTimeCodec;
import org.jetlinks.community.mapping.annotation.LocalDateTimeCodec;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EasyormEnhanceConfiguration {

    @Autowired
    public void enhanceJpaEntityTableMetadataParser(JpaEntityTableMetadataParser parser) {
        DefaultValueCodecResolver commons = DefaultValueCodecResolver.COMMONS;
        commons.register(EnhanceDateTimeCodec.class, (field, ann) -> new org.jetlinks.community.codec.EnhanceDateTimeCodec(ann.format(), field.getPropertyType()));
        commons.register(LocalDateTimeCodec.class, (field, ann) -> new org.jetlinks.community.codec.LocalDateTimeCodec(ann.format(), field.getPropertyType()));
        parser.setValueCodecResolver(commons);
    }
}
